package com.ruoyi.web.controller.market.risk;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.RiskConfigFilterInfo;
import com.ruoyi.risk.service.IRiskConfigFilterInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.RiskConfigFilterInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风控条件过滤配置Controller
 * 
 * @author ruoyi
 * @date 2023-07-25
 */
@Controller
@RequestMapping("/risk/info")
public class RiskConfigFilterInfoController extends BaseController
{
    private String prefix = "risk/info";

    @Autowired
    private IRiskConfigFilterInfoService riskConfigFilterInfoService;

    @RequiresPermissions("risk:info:view")
    @GetMapping("/{configId}")
    public String info(@PathVariable("configId") String configId, ModelMap mmap)
    {
        mmap.put("configId", configId);
        return prefix + "/info";
    }

    /**
     * 查询风控条件过滤配置列表
     */
    @RequiresPermissions("risk:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskConfigFilterInfo riskConfigFilterInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = riskConfigFilterInfoService.selectRiskConfigFilterInfoListMap(riskConfigFilterInfo);
        mapList = new RiskConfigFilterInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出风控条件过滤配置列表
     */
    @RequiresPermissions("risk:info:export")
    @Log(title = "风控条件过滤配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskConfigFilterInfo riskConfigFilterInfo)
    {
        List<RiskConfigFilterInfo> list = riskConfigFilterInfoService.selectRiskConfigFilterInfoList(riskConfigFilterInfo);
        ExcelUtil<RiskConfigFilterInfo> util = new ExcelUtil<RiskConfigFilterInfo>(RiskConfigFilterInfo.class);
        return util.exportExcel(list, "风控条件过滤配置数据");
    }

    /**
     * 新增风控条件过滤配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风控条件过滤配置
     */
    @RequiresPermissions("risk:info:add")
    @Log(title = "风控条件过滤配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskConfigFilterInfo riskConfigFilterInfo)
    {
        return toAjax(riskConfigFilterInfoService.insertRiskConfigFilterInfo(riskConfigFilterInfo));
    }

    /**
     * 修改风控条件过滤配置
     */
    @RequiresPermissions("risk:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RiskConfigFilterInfo riskConfigFilterInfo = riskConfigFilterInfoService.selectRiskConfigFilterInfoById(id);
        mmap.put("riskConfigFilterInfo", riskConfigFilterInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存风控条件过滤配置
     */
    @RequiresPermissions("risk:info:edit")
    @Log(title = "风控条件过滤配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskConfigFilterInfo riskConfigFilterInfo)
    {
        return toAjax(riskConfigFilterInfoService.updateRiskConfigFilterInfo(riskConfigFilterInfo));
    }

    /**
     * 删除风控条件过滤配置
     */
    @RequiresPermissions("risk:info:remove")
    @Log(title = "风控条件过滤配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskConfigFilterInfoService.deleteRiskConfigFilterInfoByIds(ids));
    }
}
